#include "windows.h"
#include "types.h"
#include "main.h"
#include <string>


char IniName[MAX_PATH];

void GetINIPath()
{
	char vPath[MAX_PATH], *szPath, currDir[MAX_PATH];
	/*if (*vPath)
	szPath = vPath;
	else
	{*/
	char *p;
	ZeroMemory(vPath, sizeof(vPath));
	GetModuleFileName(NULL, vPath, sizeof(vPath));
	p = vPath + lstrlen(vPath);
	while (p >= vPath && *p != '\\') p--;
	if (++p >= vPath) *p = 0;
	szPath = vPath;
	if (strlen(szPath) + strlen("pcejin.ini") < MAX_PATH)
	{
		sprintf(IniName, "%s\pcejin.ini",szPath);
	} else if (MAX_PATH> strlen(".\\pcejin.ini")) {
		sprintf(IniName, ".\\pcejin.ini");
	} else
	{
		memset(IniName,0,MAX_PATH) ;
	}
}

void WritePrivateProfileBool(char* appname, char* keyname, bool val, char* file)
{
	char temp[256] = "";
	sprintf(temp, "%d", val?1:0);
	WritePrivateProfileString(appname, keyname, temp, file);
}

bool GetPrivateProfileBool(const char* appname, const char* keyname, bool defval, const char* filename)
{
	return GetPrivateProfileInt(appname,keyname,defval?1:0,filename) != 0;
}

void WritePrivateProfileInt(char* appname, char* keyname, int val, char* file)
{
	char temp[256] = "";
	sprintf(temp, "%d", val);
	WritePrivateProfileString(appname, keyname, temp, file);
}
